package com.sip.stream.helper;

import android.content.Context;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.util.Log;

import com.sip.stream.utils.ZFYStatusType;

public class ZFYUsbDeviceHelper {
    public static boolean checkIsUVCUsbDevice(UsbDevice usbDevice)
    {
        Log.i("ZFYUsbDeviceHelper", "" + usbDevice.toString());
        if (usbDevice.getProductName() == null || !(usbDevice.getProductName().contains("Camera") || usbDevice.getProductName().contains("camera")))
        {
            if (usbDevice.getManufacturerName() == null || !(usbDevice.getManufacturerName().contains("Camera") || usbDevice.getManufacturerName().contains("camera")))
            {
                if (usbDevice.getSerialNumber() == null || !(usbDevice.getSerialNumber().contains("Camera") || usbDevice.getSerialNumber().contains("camera")))
                {
                    return (usbDevice.getDeviceClass() == 239 && usbDevice.getDeviceSubclass() == 2) || (usbDevice.getDeviceClass() == 1 && usbDevice.getDeviceSubclass() == 5);
                }
                return true;
            }
            return true;
        }
        return true;
    }

    public static boolean checkIsUVCIn(Context context)
    {
        for (UsbDevice usbDevice : ((UsbManager) context.getSystemService(Context.USB_SERVICE)).getDeviceList().values()) {
            Log.i("ZFYUsbDeviceHelper", "" + usbDevice.toString());
            if (usbDevice.getProductName() != null && (usbDevice.getProductName().contains("Camera") || usbDevice.getProductName().contains("camera"))) {
                return true;
            }
            if (usbDevice.getManufacturerName() != null && (usbDevice.getManufacturerName().contains("Camera") || usbDevice.getManufacturerName().contains("camera"))) {
                return true;
            }
            if (usbDevice.getSerialNumber() != null && (usbDevice.getSerialNumber().contains("Camera") || usbDevice.getSerialNumber().contains("camera"))) {
                return true;
            }
            if ((usbDevice.getDeviceClass() == 239 && usbDevice.getDeviceSubclass() == 2) || (usbDevice.getDeviceClass() == 1 && usbDevice.getDeviceSubclass() == 5)) {
                return true;
            }
        }
        return false;
    }
}
